package com.mycc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mycc.common.Code;
import com.mycc.common.Result;
import com.mycc.damin.TbGuides;
import com.mycc.damin.TbTours;
import com.mycc.service.ToursService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ToursController {
    @Autowired
    private ToursService tourService;

    //添加
    @PostMapping("/addTours")
    public Result addTours(@RequestBody TbTours tours) {
        boolean flag = tourService.addTours(tours);
        if (flag) {
            return new Result(Code.ADD_OK, "ok", flag);
        } else {
            return new Result(Code.ADD_FAIL, "error", flag);
        }
    }

    //删除
    @DeleteMapping("/deleteTours/{id}")
    public Result deleteGuide(@PathVariable("id") int id) {
        boolean flag = tourService.deleteTours(id);
        if (flag) {
            return new Result(Code.DELETE_OK, "ok", flag);
        } else {
            return new Result(Code.DELETE_FAIL, "error", flag);
        }
    }

    //查询全部旅游团
        @GetMapping("/selAllTours/{pageNumber}/{pageSize}")
    public IPage<TbTours> selAll(@PathVariable Integer pageNumber, @PathVariable Integer pageSize) {
        return tourService.selAllTours(pageNumber, pageSize);
    }

    //通过名字查询旅游团
    @GetMapping("/selByNameTour/{name}")
    public Result selByNameTour(@PathVariable("name") String name) {
        List<TbTours> list = tourService.selByNameTours(name);
        if (list != null) {
            return new Result(Code.SELECT_OK, "ok", list);
        } else {
            return new Result(Code.SELECT_FAIL, "error", list);
        }
    }

    //通过地区查询旅游团
    @GetMapping("/selByLocationTour/{location}")
    public Result selByLocationTour(@PathVariable("location") String location) {
        List<TbTours> list = tourService.selByLocationTours(location);
        if (list != null) {
            return new Result(Code.SELECT_OK, "ok", list);
        } else {
            return new Result(Code.SELECT_FAIL, "error", list);
        }
    }

    //通过id修改旅游团
    @PutMapping("/updateTours/{id}")
    public Result updateTours(@PathVariable("id") int id, @RequestBody TbTours tours) {
        boolean flag = tourService.updateTours(id, tours);
        if (flag) {
            return new Result(Code.SET_OK, "ok", flag);
        } else {
            return new Result(Code.SET_FAIL, "error", flag);
        }
    }
}